package jjn.round1;

/**
 * @author Jjn
 * @since 2023/4/30 22:50
 */
public class LeetCode198_Rob {
    public int rob(int[] nums) {
        // 1, 2, 3, ..., n
        // 1, ..., f(k-2), f(k-1), f(k), ... , f(n)
        if (nums == null || nums.length == 0) {
            return 0;
        }
        if (nums.length == 1) {
            return nums[0];
        }
        int[] f = new int[nums.length];
        f[0] = nums[0];
        f[1] = Math.max(nums[0], nums[1]);
        for (int i = 2; i < nums.length; i++) {
            f[i] = Math.max(f[i - 1], f[i - 2] + nums[i]);
        }
        return f[nums.length - 1];
    }
}
